\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{amsmath}

\begin{document}
	\begin{tikzpicture}
		\begin{axis}[
			axis lines = middle,
			xmin=-1.5, xmax=2.5,
			ymin=-3.5, ymax=2,
			xtick={-1, 0, 1, 2},
			xticklabels={},
			ytick={-1,0,1,2},
			yticklabels={,,}, % 隐藏所有y轴标签
			clip mode=individual,
			xlabel={$x$},
			ylabel={$y$},
			width=12cm,
			height=8cm,
			every axis x label/.style={at={(ticklabel* cs:1)}, anchor=north west},
			every axis y label/.style={at={(ticklabel* cs:1)}, anchor=south east},
			grid=none
			]
			
			% 定义函数: y = x^3 - 2x^2 - x + 1
			\addplot [
			thick, 
			domain=-1.3:2.3, 
			samples=300
			] {x^3 - 2*x^2 - x + 1};
			
			% 函数标签
			\node at (0.5,1.5) {$y = f(x)$};
			
			% 标记点A(-1, f(-1)) = (-1, -1)
			\coordinate (A) at (-1, -1);
			\fill (A) circle (2pt) node[above right] {A};
			\draw [dashed] (A) -- (A|-{0,0});
			\node[above] at (-1, 0) {$a$};
			
			% 标记端点B(2, f(2)) = (2, -1)
			\coordinate (B) at (2, -1);
			\fill (B) circle (2pt) node[above left] {B};
			\draw [dashed] (B) -- (B|-{0,0});
			\node[above] at (2, 0) {$b$};
			
			% 标记最高点C(x≈-0.21525) - 红色水平切线
			\pgfmathsetmacro{\xC}{-0.21525}
			\pgfmathsetmacro{\yC}{(\xC)^3 - 2*(\xC)^2 - \xC + 1} % 精确计算y值
			\coordinate (C) at (\xC, \yC);
			\fill (C) circle (2pt) node[above] {$C$};
			\draw [dashed] (C) -- (C|-{0,0});
			\draw [red, shorten >= -1.2cm, shorten <= -0.5cm] (C) -- (0,\yC); % 红色水平切线
			\node[below] at (\xC, 0) {$\xi$};
			
			% 标记最低点D(x≈1.54858) - 红色水平切线
			\pgfmathsetmacro{\xD}{1.54858}
			\pgfmathsetmacro{\yD}{(\xD)^3 - 2*(\xD)^2 - \xD + 1} % 精确计算y值
			\coordinate (D) at (\xD, \yD);
			\fill (D) circle (2pt) node[below] {$D$};
			\draw [dashed] (D) -- (D|-{0,0});
			\draw [red, shorten >= -0.8cm, shorten <= -0.8cm] (D) -- (2,\yD); % 红色水平切线
			
			% 连接A和B - 蓝色实线
			\draw [blue, solid] (A) -- (B);
			
		\end{axis}
	\end{tikzpicture}
\end{document}